package cn.glow.readingcloud.book.feign.fallback;


import cn.glow.readingcloud.book.feign.client.BookClient;
import cn.glow.readingcloud.common.result.Result;
import cn.glow.readingcloud.common.result.ResultUtil;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import  cn.glow.readingcloud.common.pojo.Book;


/**
 * @Author Glow
 * @Date 2023-04-16 14:34:20
 * @Description
 * @Version 1.0
 */
@Component
public class BookClientFallBack implements FallbackFactory<BookClient> {
    private static final Logger LOGGER = LoggerFactory.getLogger(BookClientFallBack.class);

    @Override
    public BookClient create(Throwable throwable) {
     return new BookClient() {
         @Override
         public Result<Book> getBookById(String bookId) {
             LOGGER.error("获取图书[{}]失败：{}", bookId, throwable.getMessage());
             return ResultUtil.notFound(null);
         }
     };
    }
}
